package com.qf.utils;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;

public class MyExceptioin implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        e.printStackTrace();//打印异常栈
        //创建一个ModelAndView
        ModelAndView mv = new ModelAndView();
        //识别异常
        if (e instanceof SQLException) {
            mv.setViewName("redirect:/error/error1.jsp");
        } else if (e instanceof ClassNotFoundException) {
            mv.setViewName("redirect:/error/error2.jsp");
        } else {
            mv.setViewName("redirect:/error/error.jsp");
        }
        return mv;
    }
}
